package algorithm.recursive;

import java.util.Scanner;

/**
 * @author keyer
 * @Description : 描述
 * Created by cyd on 2021-06-15 11:45:21
 */
public class TowerOfHanoi {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("enter num of disks:");
        int in = scanner.nextInt();

        System.out.println("the moves are :");
        moveDisks(in,'A','B','C');
    }

    public static void moveDisks(int n, char fromTower, char toTower, char auxTower) {
        if (n == 1) {
            System.out.println("move disk " + n + " from tower " + fromTower + " to tower " + toTower);
        } else {
            moveDisks(n - 1, fromTower, auxTower, toTower);
            System.out.println("move disk " + n + " from tower " + fromTower + " to tower " + toTower);
            moveDisks(n - 1, auxTower, toTower, fromTower);
        }
    }
}
